﻿using System.Runtime.Serialization;
using System.Text;

namespace RockBus.Monitoring.DataContracts.Configuration
{
    /// <summary>
    /// Specifies the configuration for the performance counter instance.
    /// </summary>
    [DataContract(Namespace = NamespaceConstants.MonitoringNamespace)]
    public class PerformanceCounterInstanceConfiguration : PerformanceCounterConfigurationBase
    {
        public const string PerformanceCounterInstanceNameFormat = @"{0}({2})\{1}";

        public PerformanceCounterInstanceConfiguration()
            : base()
        {
        }

        public PerformanceCounterInstanceConfiguration(PerformanceCounterConfigurationBase pccb, string instanceName)
            : base()
        {
            this.CategoryName = pccb.CategoryName;
            this.CounterName = pccb.CounterName;
            this.InstanceName = instanceName;
        }

        /// <summary>
        /// The performance counter instance name.
        /// </summary>
        [DataMember(IsRequired = true)]
        public string InstanceName { get; set; }

        ///
        /// The full name of the performance counter instance. In the same format as perfmon or logman are using (i.e. 'Processor(_Total)\% Processor Time').
        ///
        public override string FullName
        {
            get { return string.Format(PerformanceCounterInstanceNameFormat, this.CategoryName, this.CounterName, this.InstanceName); }
        }

        public override string ToString()
        {
            var sb = new StringBuilder(base.ToString());
            sb.AppendLine(string.Format("InstanceName: {0}", this.InstanceName ?? string.Empty));
            return sb.ToString();
        }
    }
}